# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgbase="c-ares"
pkgname=("libcares" "libcares-devel")
pkgver=1.17.1
pkgrel=1
pkgdesc="C library that performs DNS requests and name resolves asynchronously (libraries)"
arch=('i686' 'x86_64')
url="https://c-ares.haxx.se/"
license=("MIT")
makedepends=("gcc")
depends=("gcc-libs")
options=('staticlibs')
source=("https://c-ares.haxx.se/download/${pkgbase}-${pkgver}.tar.gz"{,.asc}
        "https://c-ares.haxx.se/license.html")
sha256sums=('d73dd0f6de824afd407ce10750ea081af47eba52b8a6cb307d220131ad93fc40'
            'SKIP'
            '41215a3adeb9dcb308df48ed63faea7eb34cd9e944139123623e79fb8e656712')
validpgpkeys=('27EDEAF22F3ABCEB50DB9A125CC908FDB71E12C2')

prepare() {
  cd "${srcdir}/${pkgbase}-${pkgver}"
  autoreconf -ivf
}

build() {
  cd "${srcdir}/${pkgbase}-${pkgver}"
  ./configure \
    --prefix=/usr \
    --enable-shared \
    --enable-static
  make
  make DESTDIR="${srcdir}/dest" install
  install -Dm644 ${srcdir}/license.html ${srcdir}/dest/usr/share/licenses/c-ares/license.html
}

check() {
  cd "${srcdir}/${pkgbase}-${pkgver}"
  make -k check
}

package_libcares() {
  groups=('libraries')

  mkdir -p ${pkgdir}/usr/bin
  cp -rf ${srcdir}/dest/usr/bin ${pkgdir}/usr/

  mkdir -p ${pkgdir}/usr/share
  cp -rf ${srcdir}/dest/usr/share ${pkgdir}/usr/
}

package_libcares-devel() {
  pkgdesc="c-ares headers and libraries (development)"
  groups=('development')
  depends=("libcares=${pkgver}")

  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
}
